Skip to content

[KDA] Add TLE inference backend for NVIDIA H800 with up to 1.41x speedup - #1075

Open
kuoihao wants to merge 2 commits into
fla-org:mainfrom
kuoihao:feat/tle-kda-backend
Open

[KDA] Add TLE inference backend for NVIDIA H800 with up to 1.41x speedup#1075
kuoihao wants to merge 2 commits into
fla-org:mainfrom
kuoihao:feat/tle-kda-backend

Conversation

@kuoihao

@kuoihao kuoihao commented Jul 30, 2026

Copy link
Copy Markdown

Summary

This PR adds a Triton TLE inference backend for chunk_kda.

It uses the existing fla.ops.kda.chunk_kda entry point and is selected through backend dispatch. TLE has higher priority than FlashKDA; unsupported inputs automatically fall back to FlashKDA or the default Triton implementation.

Main changes:

  • Add a TMA + warp-specialized TLE forward kernel.
  • Support dense and variable-length inference.
  • Add correctness tests and an inference benchmark entry.
  • Add FLA_TLE_KDA=0 to opt out.

Implementation and optimization analysis:
https://mp.weixin.qq.com/s/0KUi9436u9AhzpuBqB_Xww
flagtree:
https://github.com/flagos-ai/FlagTree
install:

# Note: First install PyTorch, then execute the following commands
python3 -m pip uninstall -y triton  # Repeat the cmd until fully uninstalled
RES="--index-url=https://resource.flagos.net/repository/flagos-pypi-hosted/simple"
python3.12 -m pip install flagtree===0.6.0 $RES

Requirements

  • NVIDIA Hopper GPU
  • Triton >= 3.6 with TLE
  • torch.inference_mode()
  • BF16
  • K = V = 128
  • use_qk_l2norm_in_kernel=True
  • use_gate_in_kernel=True
  • use_beta_sigmoid_in_kernel=True
  • safe_gate=True
  • state_v_first=True

Performance

Environment: NVIDIA H800, CUDA 13.0, PyTorch 2.13.0+cu130.

B T H D TLE (ms) FlashKDA (ms) Speedup
1 8192 96 128 1.093 1.539 1.41x
2 16384 16 128 1.490 2.066 1.39x
4 2048 16 128 0.242 0.334 1.38x
4 4096 64 128 1.284 1.745 1.36x

TLE is 1.36x–1.41x faster than FlashKDA on the tested shapes.

# TLE
FLA_TLE_KDA=1 FLA_FLASH_KDA=0 FLA_TILELANG=0 \
python -m benchmarks.ops.run --op chunk_kda_inference --modes fwd

# FlashKDA
FLA_TLE_KDA=0 FLA_FLASH_KDA=1 FLA_TILELANG=0 \
python -m benchmarks.ops.run --op chunk_kda_inference --modes fwd

Correctness

All TLE tests passed:

8 passed, 83 deselected
python -m pytest tests/ops/test_kda.py -k 'tle_kda' -v

@kuoihao kuoihao changed the title [KDA] Add TLE inference backend for NVIDIA Hopper [KDA] Add TLE inference backend for NVIDIA Hopper with up to 1.41x speedup Jul 30, 2026
@kuoihao kuoihao changed the title [KDA] Add TLE inference backend for NVIDIA Hopper with up to 1.41x speedup [KDA] Add TLE inference backend for NVIDIA H800 with up to 1.41x speedup Jul 30, 2026
@zhiyuan1i zhiyuan1i added needs-verification Lacks real execution evidence (CI skipped / no before-after data) performance labels Aug 14, 2026
@zhiyuan1i

Copy link
Copy Markdown
Collaborator

Sorry for the late response.

My main concern is maintenance cost over time. TileLang is still a moving target: a compiler version bump can turn into compile errors or, worse, silent numerical errors. Meanwhile the Triton baseline for KDA is still evolving quickly, so a parallel TLE implementation risks going stale and drifting out of sync with the reference path.

Before we take on a second backend to maintain, could you share how you see this staying correct over time — e.g. is there test/CI coverage that would catch drift from the Triton baseline, and how tightly does the TLE version track it?

@kuoihao

kuoihao commented Aug 18, 2026

Copy link
Copy Markdown
Author

Thanks for the review. I understand that TileLang was mentioned as an example of the long-term maintenance and compiler-upgrade risks involved.

This PR already includes reproducible TLE correctness and performance commands:

Performance:

# TLE
FLA_TLE_KDA=1 FLA_FLASH_KDA=0 FLA_TILELANG=0 \
python -m benchmarks.ops.run \
  --op chunk_kda_inference --modes fwd

# FlashKDA
FLA_TLE_KDA=0 FLA_FLASH_KDA=1 FLA_TILELANG=0 \
python -m benchmarks.ops.run \
  --op chunk_kda_inference --modes fwd

Correctness:

python -m pytest tests/ops/test_kda.py -k 'tle_kda' -v

To continuously catch compilation, numerical, or performance regressions caused by changes in the Triton baseline or FlagTree upgrades, I can integrate these commands into the existing H100 CI and pin it to the validated flagtree==0.6.0. Future FlagTree upgrades would explicitly trigger the same validation through a version update.

Would you prefer me to add dedicated TLE correctness and performance CI coverage in this PR? If this direction sounds appropriate, I will follow up with the detailed CI design and local validation results in my next update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-verification Lacks real execution evidence (CI skipped / no before-after data) performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants